/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao;

import cn.ekuma.data.dao.BaseDAO;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import com.openbravo.bean.StockDiary;

/**
 *
 * @author Administrator
 */
public class StockDiaryDAO extends BaseDAO<StockDiary>{

    public StockDiaryDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
    	return new TableDefinition(s, "STOCKDIARY", new Field[] {
				new Field("ID", Datas.STRING, Formats.STRING),
				new Field("DATENEW", Datas.TIMESTAMP, Formats.TIMESTAMP),
				new Field("REASON", Datas.STRING, Formats.STRING),
				new Field("LOCATION", Datas.STRING,Formats.STRING),
				new Field("PRODUCT", Datas.STRING,Formats.STRING),
				new Field("ATTRIBUTESETINSTANCE_ID", Datas.STRING,Formats.STRING),
				new Field("UNITS", Datas.DOUBLE, Formats.DOUBLE),
				new Field("PRICE", Datas.DOUBLE, Formats.DOUBLE),
				new Field("LOTNO", Datas.STRING,Formats.STRING),	          
				new Field("VALIDITYDATE", Datas.TIMESTAMP, Formats.TIMESTAMP),
				new Field("BOMID", Datas.STRING, Formats.STRING)
				},
				new int[] {0});
    }

    @Override
    public void writeInsertValues(DataWrite dp, StockDiary obj) throws BasicException {
         dp.setString(1,obj.getId());
         dp.setTimestamp(2,obj.getDate());
         dp.setString(3,obj.getReason());
         dp.setString(4,obj.getLocation());
         dp.setString(5,obj.getProductID());
         dp.setString(6,obj.getProductAttSetInstId());
         dp.setDouble(7,obj.getMultiply());
         dp.setDouble(8,obj.getPrice());
         dp.setString(9,obj.getLotNo());
         dp.setTimestamp(10,obj.getValidityDate());
         dp.setString(11,obj.getBomId());
    }

    public StockDiary readValues(DataRead dr,StockDiary diary) throws BasicException {
    	if(diary==null)
    		diary=new StockDiary();
    	diary.setId(dr.getString(1));
    	diary.setDate(dr.getTimestamp(2));
    	diary.setReason(dr.getString(3));
    	diary.setLocation(dr.getString(4));
    	diary.setProductID(dr.getString(5));
    	diary.setProductAttSetInstId(dr.getString(6));
    	diary.setMultiply(dr.getDouble(7));
    	diary.setPrice(dr.getDouble(8));
    	diary.setLotNo(dr.getString(9));
    	diary.setValidityDate(dr.getTimestamp(10));
    	diary.setBomId(dr.getString(11));
    	return diary;
    }

    @Override
    public Class getSuportClass() {
        return StockDiary.class;
    }

}
